package RenRen;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

public class test {

	/**
	 * @param args
	 * @throws URISyntaxException 
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void main(String[] args) throws URISyntaxException, ClientProtocolException, IOException {
		// TODO Auto-generated method stub
		HttpClient hc=new DefaultHttpClient();
		new test().setParam();
	}
	//设置参数
	public  void setParam() throws URISyntaxException, IOException{
		List<NameValuePair> qparams = new ArrayList<NameValuePair>();
		qparams.add(new BasicNameValuePair("rmt_user", "sa33"));
		qparams.add(new BasicNameValuePair("lx", "400400"));
		qparams.add(new BasicNameValuePair("rq", "2011-6-19"));
		qparams.add(new BasicNameValuePair("djbh", "112212 "));
		qparams.add(new BasicNameValuePair("pizhwh","国药准字H20084257"));
	
//		URI uri = URIUtils.createURI("http", "localhost:8080/fda", -1,"deliverCompSave.action", 
//		URLEncodedUtils.format(qparams, "UTF-8"), null);
		HttpPost httpPost=new HttpPost("http://localhost:8080/fda/deliverCompSave.action");
		HttpClient httpclient = new DefaultHttpClient();
		UrlEncodedFormEntity urlentity = new UrlEncodedFormEntity(qparams, "UTF-8");
		httpPost.setEntity(urlentity);
		HttpResponse response = httpclient.execute(httpPost);
		HttpEntity entity = response.getEntity();
		
		if (entity != null) {
		    InputStream instream = entity.getContent();
		    String line="";
		    String result="";
		    BufferedReader in = new BufferedReader(new InputStreamReader(
		    		instream,"utf-8"));
            while ((line = in.readLine()) != null) {
                result = result + "\n" + line;
            }
		    
		    System.out.println(result);
		    int byteOne = instream.read();
		    int byteTwo = instream.read();
		    // Do not need the rest
		    httpPost.abort();
		}
		
		
	}
	
	
	

}
